﻿using System;
using IInject.Internal;
using IInject.Registration;
using IInject.Resolution;

namespace IInject.Extensibility
{
	/// <summary>
	/// A base class for implementing an extension.
	/// </summary>
	public abstract class ContainerExtension : ContainerMember, IExtension
	{
		protected ContainerExtension(IContainer container) : base(container)
		{
			if (!(container is IExtensible))
			{
				throw new InvalidOperationException("IContainer implementation must be extensible!");
			}

			var extensible = (IExtensible)container;
			extensible.ItemRegistered += ItemRegistered;
			extensible.ItemRegistering += ItemRegistering;
			extensible.ItemResolving += ItemResolving;
		}

		/// <summary>
		/// The method that is called when a <see cref="RegistryContext" /> is being registered.
		/// </summary>
		/// <param name="context">The context.</param>
		public abstract void ItemRegistering(RegistryContext context);

		/// <summary>
		/// The method that is called when a <see cref="RegistryContext" /> has been registered.
		/// </summary>
		/// <param name="context">The context.</param>
		public abstract void ItemRegistered(RegistryContext context);

		/// <summary>
		/// The method that is called when a <see cref="RegistryContext" /> is being resolved.
		/// </summary>
		/// <param name="context">The context.</param>
		public abstract void ItemResolving(TypeDependency dependency);
	}
}
